package com.example.module_home.network

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import com.example.module_home.databinding.HomeActivityCoroutineFlowBinding
import me.hgj.jetpackmvvm.ext.util.toJson

class CoroutineFlowActivity : AppCompatActivity() {

    private lateinit var binding: HomeActivityCoroutineFlowBinding
    private val viewModel: CoroutineFlowViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = HomeActivityCoroutineFlowBinding.inflate(LayoutInflater.from(this), null, false)
        setContentView(binding.root)


        viewModel.netResponseData.observe(this, Observer {
            binding.dataTextview.text = it.size.toString()
        })

        viewModel.album.observe(this, Observer {
            binding.dataTextview.text = it.toString()
        })


        binding.fetchButton.setOnClickListener {

            viewModel.fetchData()
        }

    }


}